package game.efekti;

import util.INIGroup;
import util.Util;
import game.Character;
import game.EffectStage;
import game.Item;
import game.MagicEffect;
import game.Item.ItemType;

public class AddResistance extends MagicEffect {
	int inc = 0;
	int res = 0;
	
	@Override
	public boolean loadFromFile(INIGroup grupa) {
		tag = grupa.getString("Tag");
		inc = grupa.getInteger("Bonus", 0);
		res = grupa.getInteger("DamageType", 0);
		return true;
	}

	@Override
	public void init() {}

	@Override
	public EffectStage getStage() {
		return EffectStage.ConstantEffect;
	}

	@Override
	public boolean canHazTip(ItemType tip) {
		return tip != Item.ItemType.POTION;
	}

	@Override
	public void doEffect(Character caster, Character target) {
		switch(res)
		{
		case 0: caster.setFireResistance((int) (caster.getFireResistance() + inc)); break;
		case 1: caster.setColdResistance((int) (caster.getColdResistance() + inc)); break;
		case 2: caster.setLightningResistance((int) (caster.getLightningResistance() + inc)); break;
		}
	}

	private static String getResString(int i)
	{
		switch(i)
		{
		case 0: return "fire";
		case 1: return "cold";
		case 2: return "lightning";
		}
		return "";
	}
	
	@Override
	public String toString() {
		return "+" + inc + "% " + getResString(res) + " resistance";
	}

	@Override
	public void generateForLevel(int lvl) {
		res = Util.getRndInt(0, 2);
		inc = Util.getRndInt(lvl / 2 + 1, lvl);
		if(inc > 80) inc = 80;
	}

	@Override
	public boolean stacksWith(MagicEffect e) {
		if(e instanceof AddResistance)
			return ((AddResistance)e).res == res;
		return false;
	}

	@Override
	public void absorb(MagicEffect e) {
		inc += ((AddResistance)e).inc;
		if(inc > 80) inc = 80;
	}

}
